package com.yuyou.fn.platform.service.impl;

import com.yuyou.fn.common.util.BeanUtils;
import org.springframework.stereotype.Service;

import com.yuyou.fn.platform.mapper.CityMapper;
import com.yuyou.fn.platform.entity.City;
import com.yuyou.fn.platform.service.ICityService;
import com.github.wens.framework.service.impl.SuperServiceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * City 表数据服务层接口实现类
 *
 */
@Service
public class CityServiceImpl extends SuperServiceImpl<CityMapper, City,Long> implements ICityService {

    @Override
    public Map<Long, City> findAllCityMapById() {
        List<City> cityList=this.findListByExample(City.createExample());
        return BeanUtils.toMap(cityList,"cityId");
    }

    @Override
    public Map<String, City> findAllCityMapByProvinceNameCityName() {
        Map<String,City> map=new HashMap<>();
        List<City> cityList=this.findListByExample(City.createExample());
        if (cityList!=null && !cityList.isEmpty()){
            for (City city:cityList){
                String key=city.getProvinceName().replaceAll("省","")+"_"+city.getCityName().replaceAll("市","");
                map.put(key,city);
            }
        }
        return map;
    }
}